package aimozg.joglfw.bones;

/**
* Created by IntelliJ IDEA.
* User: aimozg
* Date: 02.01.11
* Time: 18:04
*/
public class KeyPoint {
	public final double px;
	public final double py;
	public final double pz;
	public final double rotAngle;
	public final double tx;
	public final double ty;
	public final double tz;
	public KeyPoint next = null;
	public double duration = 1.0;

	public KeyPoint(Bone bone) {
		this(bone.px,bone.py,bone.pz,bone.rotAngle,bone.tx,bone.ty,bone.tz);
	}

	public KeyPoint clone(){
		return new KeyPoint(px,py,pz,rotAngle,tx,ty,tz);
	}

	public void setNext(KeyPoint next){
		this.next = next;
	}

	public KeyPoint(double px, double py, double pz, double rotAngle, double tx, double ty, double tz) {
		this.px = px;
		this.py = py;
		this.pz = pz;
		this.rotAngle = rotAngle;
		this.tx = tx;
		this.ty = ty;
		this.tz = tz;
	}

	public void apply(Bone bone, double progress){
		if (duration <= 0.0){
			progress = 1.0;
		} else {
			progress = progress/duration;
		}
		if (next != null & progress > 0.0){
			if (progress > 1.0) {
				progress = 1.0;
			}
			double p0 = 1.0-progress;
			bone.px = p0*px+progress*next.px;
			bone.py = p0*py+progress*next.py;
			bone.pz = p0*pz+progress*next.pz;
			bone.rotAngle = p0*rotAngle +progress*next.rotAngle;
			bone.tx = p0*tx+progress*next.tx;
			bone.ty = p0*ty+progress*next.ty;
			bone.tz = p0*tz+progress*next.tz;
		}
	}

	public KeyPoint modify(double dpx, double dpy, double dpz, double dRotAngle, double dtx, double dty, double dtz) {
		return new KeyPoint(px+dpx,py+dpy,pz+dpz,rotAngle+dRotAngle,tx+dtx,ty+dty,tz+dtz);
	}
	public KeyPoint reposition(double dpx, double dpy){
		return modify(dpx,dpy,0,0,0,0,0);
	}
	public KeyPoint rotate(double angle){
		return modify(0,0,0,angle,0,0,0);
	}
	public KeyPoint translate(double dtx,double dty){
		return modify(0,0,0,0,dtx,dty,0);
	}
}
